package com.cloud.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
public class AuthorizationController {
    @Autowired
    private OAuth2AuthorizedClientService clientService;

    @GetMapping("/test01")
    public String test01() {
        return "test01";
    }

    @GetMapping("/token")
    @ResponseBody
    public OAuth2User user(Principal principal) {
        if (!(principal instanceof OAuth2AuthenticationToken token)) {
            return null;
        }
        return token.getPrincipal();
    }

    @GetMapping("/test02")
    public String test02() {


        return "test02";
    }

    @GetMapping("/users/userinfo")

    public String app() {


        return "app";
    }

}

